import axios from '../../plugins/axios.js'

const state = {
	home:[] ,  //相当于data:[]
	banner:[]
}

const actions = {
	home({state,commit},{_limit,_page}){
		//判断payload是不是数组
		axios.get(`/news/home`,{params:{_limit:_limit||20,_page:_page||1}}).then(
			res=>{
				//success ?->判断
				commit('home',res.data)
			}
		)
	},
	banner({state,commit},{_limit,_page}){
		//判断payload是不是数组
		axios.get(`/news/banner`,{params:{_limit:_limit||5,_page:_page||1}}).then(
			res=>{
				//success ?->判断
				commit('banner',res.data)
			}
		)
	}
}

const mutations = {
	home:(state,payload)=>state.home=payload,
	banner:(state,payload)=>state.banner=payload
}

export default {
	namespaced:true,
	state,actions,mutations
}